package com.zl.cms.model;


import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-3-6 Time: 下午1:46
 */
@Entity
@Table(name = "t_attachement")
public class Attachment {
  private int id;
  /**
   * 附件上传后新名称
   */
  private String newName;
  /**
   * 附件上传前原始名称
   */
  private String oldName;

  /**
   * 附件后缀名
   */
  private String suffix;

  /**
   * 附件类型,与contentType一致
   */
  private String type;
  /**
   * 附件大小
   */
  private long size;
  /**
   * 是否是主页图片
   */
  private int indexPic;
  /**
   * 该附件是否是图片类型,0表示不是，1表示是
   */
  private int img;
  /**
   * 所属文章
   */
  private Topic topic;

  /**
   * 是否是附件信息，0表示不是，1表示是，如果是附件信息就在文章的附件栏进行显示
   */
  private int attch;
  /**
   * 创建时间
   */
  private Date createDate;

  public Date getCreateDate() {
    return createDate;
  }

  public void setCreateDate(Date createDate) {
    this.createDate = createDate;
  }

  public int getAttch() {
    return attch;
  }

  public void setAttch(int attch) {
    this.attch = attch;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getNewName() {
    return newName;
  }

  public void setNewName(String newName) {
    this.newName = newName;
  }

  public String getOldName() {
    return oldName;
  }

  public void setOldName(String oldName) {
    this.oldName = oldName;
  }

  public String getSuffix() {
    return suffix;
  }

  public void setSuffix(String suffix) {
    this.suffix = suffix;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public long getSize() {
    return size;
  }

  public void setSize(long size) {
    this.size = size;
  }

  public int getIndexPic() {
    return indexPic;
  }

  public void setIndexPic(int indexPic) {
    this.indexPic = indexPic;
  }

  public int getImg() {
    return img;
  }

  public void setImg(int img) {
    this.img = img;
  }

  public Topic getTopic() {
    return topic;
  }

  public void setTopic(Topic topic) {
    this.topic = topic;
  }

  public Attachment() {}

  public Attachment(int id, String newName) {
    this.id = id;
    this.newName = newName;
  }

  // select new
  // Attachment(a.id,a.newName,a.oldName,a.suffix,a.type,a.size,a.indexPic,a.img,a.attch,a.createDate,a.topic.id)"
  public Attachment(int id, String newName, String oldName, String suffix, String type, long size,
      int indexPic, int img, int attch, Date createDate, int tid) {
    this.id = id;
    this.newName = newName;
    this.oldName = oldName;
    this.suffix = suffix;
    this.type = type;
    this.size = size;
    this.indexPic = indexPic;
    this.img = img;
    this.attch = attch;
    this.createDate = createDate;
    this.topic = new Topic();
    this.topic.setId(tid);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Attachment that = (Attachment) o;

    if (id != that.id) return false;
    if (newName != null ? !newName.equals(that.getNewName()) : that.getNewName() != null)
      return false;

    return true;
  }

  @Override
  public int hashCode() {
    int result = id;
    result = 31 * result + (newName != null ? newName.hashCode() : 0);
    return result;
  }

  @Override
  public String toString() {
    return "Attachment{" + "id=" + id + ", newName='" + newName + '\'' + ", oldName='" + oldName
        + '\'' + ", suffix='" + suffix + '\'' + ", type='" + type + '\'' + ", size=" + size
        + ", isIndexPic=" + indexPic + ", isImg=" + img + ", topic=" + topic + '}';
  }
}
